SetGfxDriver 1:Graphics 1024,600,8,2 :SetBuffer FrontBuffer() :SeedRnd MilliSecs()
Global prostir$,in1,in2,in3,in4,zzz1,hzzz1,jzzz1,focus$,tmp
in1 = CreateBank(100 ):in2 = CreateBank(100):in3 = CreateBank(100):in4 = CreateBank(100):tmp = CreateBank(100)
Dim zzz(100):Dim zzz2(100,10):Dim hzzz2(100,10):Dim hzzz(100):Dim jzzz2(100,10):Dim jzzz(100 )
prostir$="0010100101010110010111010101001011"
engine(0)

While Not KeyHit(1) Or MouseHit(2)
ClsColor 0,0,0
Cls

For t=1 To Len(prostir$)
bit$=Mid$(prostir$,t,1)
write_bit(bit$)
subprostir()
Next

For i=0 To 59:PokeByte in3,i,PeekByte(in1,i):PokeByte in4,i,PeekByte(in2,i):Next

For t=1 To Len(prostir$)
bit$=bit$+""+read_bit()
subprostir()
zzz1=zzz1+1:hzzz1=hzzz1+1:jzzz1=jzzz1+1
Next
;read_bit()
;focus_bit()

Flip
VWait 
Wend 

Function focus_bit()
End Function

Function write_bit(bit$)
If bit="1" Then
	For i=0 To 59 Step 6	
		t1=PeekByte(in1,i+0):t2=PeekByte(in1,i+1):t3=PeekByte(in1,i+2):t4=PeekByte(in1,i+3):t5=PeekByte(in1,i+4):t6=PeekByte(in1,i+5)
		e1=(t1 Xor t2) Xor t6:e2=(t2 Xor t1) Xor t5:e3=(t3 Xor t2) Xor t1
		e4=(t4 Xor t1) Xor t2:e5=(t5 Xor t4) Xor t1:e6=(t6 Xor t4) Xor t3
		PokeByte in1,i+0,e1:PokeByte in1,i+1,e2:PokeByte in1,i+2,e3:PokeByte in1,i+3,e4:PokeByte in1,i+4,e5:PokeByte in1,i+5,e6
	Next
Else 
	PokeByte in1,59,PeekByte(in1,59) Xor PeekByte(in1,0)
	For i=0 To 58:PokeByte in1,i,PeekByte(in1,i) Xor PeekByte(in1,i+1):Next
EndIf 	

For t=0 To 29
	For i=0 To 58:PokeByte in1,i,PeekByte(in1,i) Xor PeekByte(in1,i+1):Next
	PokeByte in1,59,PeekByte(in1,59) Xor PeekByte(in1,0)
Next
End Function


Function read_bit()

i=0	
t1=PeekByte(in1,i+0):t2=PeekByte(in1,i+1):t3=PeekByte(in1,i+2):t4=PeekByte(in1,i+3):t5=PeekByte(in1,i+4):t6=PeekByte(in1,i+5)

eee1=(t1 Xor t2) Xor t6:eee2=(t2 Xor t1) Xor t5:eee3=(t3 Xor t2) Xor t1
eee4=(t4 Xor t1) Xor t2:eee5=(t5 Xor t4) Xor t1:eee6=(t6 Xor t4) Xor t3

;eee1=Rand(1,4):eee2=Rand(1,4):eee3=Rand(1,4):eee4=Rand(1,4):eee5=Rand(1,4):eee6=Rand(1,4)

For it1=1 To 4
For it2=1 To 4
For it3=1 To 4
For it4=1 To 4
For it5=1 To 4
For it6=1 To 4

ee1= (it1 Xor it2) Xor it6
ee2= (it2 Xor it1) Xor it5
ee3= (it3 Xor it2) Xor it1
ee4= (it4 Xor it1) Xor it2
ee5= (it5 Xor it4) Xor it1
ee6= (it6 Xor it4) Xor it3

If  (ee1=eee1) And (ee2=eee2)And (ee3=eee3)And(ee4=eee4) And (ee5=eee5)And (ee6=eee6)Then zzz(zzz1)=zzz(zzz1)+1:zzz2(zzz1,zzz2(zzz1,100))=it1:its=it1:zzz2(zzz1,100)=zzz2(zzz1,100)+1
		;If zzz2(zzz1,100)=0 Then 
		zzz2(zzz1,99)=eee:its=eee
	Next
	Next
	Next
	Next
	Next
	Next

		If it1= eee Then jzzz(jzzz1)=jzzz(jzzz1)+1:jzzz2(jzzz1,jzzz2(jzzz1,100))=it1:jzzz2(jzzz1,100)=jzzz2(jzzz1,100)+1
		If jzzz2(jzzz1,100)=0 Then jzzz2(jzzz1,99)=eee

	Next			
;Next					
				
;Else


	
;EndIf 	



End Function

























Function engine(bt)
	For i = 0 To 59
	t = Rand(0,3):PokeByte in1,i, t:PokeByte in2,i, t
	Next
	
	If bt=1 Then
		For i=0 To 30
		zzz1=0:jzzz1=0:hzzz1=0:tycnt=0
		hzzz(i)=0:zzz(i)=0:jzzz(i)=0
		Next
		For i1=0 To 30
		For i2=0 To 10
		jzzz2(i1,i2)=0
		zzz2(i1,i2)=0
		hzzz2(i1,i2)=0
		Next
		Next
	EndIf
End Function

Function subprostir()
	For y=0 To 9
	For x=0 To 5
		Color 0,255,0:Text 30+y*9,x*9+10,PeekByte(in1,y*10+x),False ,False 
	Next
	Next

	For y=0 To 9
	For x=0 To 5
		Color 255,255,0:Text 230+y*9,x*9+10,PeekByte(in2,y*10+x),False ,False 
	Next
	Next
End Function
